package com.cloudsigns.factorymanager2.produce.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.produce.bean.Produce_ProductBean;

import java.util.ArrayList;
import java.util.List;

public class ProduceEditOrderAdapter extends BaseAdapter {
    private String TAG = ProduceEditOrderAdapter.class.getSimpleName();
    private Context context;
    private List<Produce_ProductBean> datas = new ArrayList<Produce_ProductBean>();
    private LayoutInflater inflater;

    public ProduceEditOrderAdapter(Context context, String TAG) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.TAG = TAG;
    }

    public void setData(List<Produce_ProductBean> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Produce_ProductBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_produce_edit_order, null);
            holder.tv_product_name = convertView.findViewById(R.id.tv_product_name);
            holder.tv_status = convertView.findViewById(R.id.tv_status);
            holder.tv_project_name = convertView.findViewById(R.id.tv_project_name);
            holder.tv_engineering_name = convertView.findViewById(R.id.tv_engineering_name);
            holder.tv_type = convertView.findViewById(R.id.tv_type);
            holder.tv_level = convertView.findViewById(R.id.tv_level);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Produce_ProductBean bean = datas.get(position);
        holder.tv_product_name.setText(bean.getProductName());
        holder.tv_project_name.setText(bean.getProjectName());
        holder.tv_engineering_name.setText(" / " + bean.getEngineeringName());

        if (null != bean.getLevel()) {
            CommonEnum.ProduceOrderLevel level = bean.getLevel();
            if (level == CommonEnum.ProduceOrderLevel.VERY_IMPORTANT) {
                holder.tv_level.setText(" / 一级");
            } else if (level == CommonEnum.ProduceOrderLevel.MORE_IMPORTANT) {
                holder.tv_level.setText(" / 二级");
            } else if (level == CommonEnum.ProduceOrderLevel.GENERALLY_IMPORTANT) {
                holder.tv_level.setText(" / 三级");
            } else if (level == CommonEnum.ProduceOrderLevel.NORMAL) {
                holder.tv_level.setText(" / 四级");
            }
        }

        if (null != bean.getType()) {
            if ("标准工单".equals(bean.getType())) {
                holder.tv_type.setText(" / A");
            } else if ("返工工单".equals(bean.getType())) {
                holder.tv_type.setText(" / B");
            } else if ("报废工单".equals(bean.getType())) {
                holder.tv_type.setText(" / C");
            } else if ("打样工单".equals(bean.getType())) {
                holder.tv_type.setText(" / D");
            } else if ("免费工单".equals(bean.getType())) {
                holder.tv_type.setText(" / E");
            }
        }
        if (bean.getStatus() == CommonEnum.ProduceOrderStatus.CREATED) {
            holder.tv_status.setText("");

        } else if (bean.getStatus() == CommonEnum.ProduceOrderStatus.EDIT) {
            holder.tv_status.setText(context.getResources().getString(R.string.edit));
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.color_619dd1));

        } else if (bean.getStatus() == CommonEnum.ProduceOrderStatus.EDITED) {
            holder.tv_status.setText(context.getResources().getString(R.string.edited));
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.color_2c9a2d));

        }else if (bean.getStatus() == CommonEnum.ProduceOrderStatus.SEND) {
            holder.tv_status.setText(context.getResources().getString(R.string.wait_receive));
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_FFC000));

        }else if (bean.getStatus() == CommonEnum.ProduceOrderStatus.RECEIVED) {
            holder.tv_status.setText(context.getResources().getString(R.string.already_received));
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.color_2c9a2d));

        }else if (bean.getStatus() == CommonEnum.ProduceOrderStatus.RETURNED) {
            holder.tv_status.setText(context.getResources().getString(R.string.order_back));
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.rgb_C00000));

        }else if (bean.getStatus() == CommonEnum.ProduceOrderStatus.COMPLETED) {
            holder.tv_status.setText(context.getResources().getString(R.string.order_completed));
            holder.tv_status.setTextColor(context.getResources().getColor(R.color.color_87c688));
        }
        return convertView;
    }

    private class ViewHolder {
        private TextView tv_product_name;
        private TextView tv_status;
        private TextView tv_project_name;
        private TextView tv_engineering_name;
        private TextView tv_type;
        private TextView tv_level;
    }

}
